package servlet;

import bean.Item;
import bean.ItemBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "PublishServlet", value = "/manager/PublishServlet")
public class PublishServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        String id=request.getParameter("id");
        String name=request.getParameter("name");
        String sex=request.getParameter("sex");
        String rules=request.getParameter("content");
        String place=request.getParameter("place");
        String time=request.getParameter("time");

        ItemBean itemBean=new ItemBean();
        itemBean.link();
        itemBean.loadItem();
        Item item=new Item(id,name,sex,rules,place,time);
        itemBean.insertItem(item);
        response.sendRedirect("manager_index.jsp");
    }
}
